package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.system.api.domain.SysSerialConfig;
import com.ruoyi.system.service.ISysSerialConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 流水号字段配置Controller
 *
 * @author ruoyi
 * @date 2023-04-14
 */
@Api(tags = "流水号字段配置")
@RestController
@RequestMapping("/serial/config")
public class SysSerialConfigController extends BaseController {
    @Autowired
    private ISysSerialConfigService sysSerialConfigService;

    /**
     * 查询流水号字段配置列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询流水号字段配置列表", response = SysSerialConfig.class)
    public AjaxResult list(SysSerialConfig sysSerialConfig) {
        List<SysSerialConfig> list = sysSerialConfigService.selectSysSerialConfigList(sysSerialConfig);
        return success(list);
    }

    /**
     * 导出流水号字段配置列表
     */
    @Log(title = "导出流水号字段配置列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出流水号字段配置列表")
    public void export(HttpServletResponse response, SysSerialConfig sysSerialConfig) {
        List<SysSerialConfig> list = sysSerialConfigService.selectSysSerialConfigList(sysSerialConfig);
        ExcelUtil<SysSerialConfig> util = new ExcelUtil<SysSerialConfig>(SysSerialConfig.class);
        util.exportExcel(response, list, "流水号字段配置数据");
    }

    /**
     * 获取流水号字段配置详细信息
     */
    @GetMapping(value = "/{configId}")
    @ApiOperation(value = "获取流水号字段配置详细信息", response = SysSerialConfig.class)
    public AjaxResult getInfo(@ApiParam(value = "流水号字段配置id", required = true) @PathVariable("configId") Long configId) {
        return success(sysSerialConfigService.selectSysSerialConfigByConfigId(configId));
    }

    /**
     * 新增流水号字段配置
     */
    @Log(title = "新增流水号字段配置", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增流水号字段配置")
    public AjaxResult add(@RequestBody SysSerialConfig sysSerialConfig) {
        return toAjax(sysSerialConfigService.insertSysSerialConfig(sysSerialConfig));
    }

    /**
     * 删除流水号字段配置
     */
    @Log(title = "删除流水号字段配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{configIds}")
    @ApiOperation(value = "删除流水号字段配置")
    public AjaxResult remove(@ApiParam(value = "流水号字段配置id", required = true) @PathVariable Long[] configIds) {
        return toAjax(sysSerialConfigService.deleteSysSerialConfigByConfigIds(configIds));
    }
}
